# Copyright (c) 2012 Nathan Grubb
# Available under the new BSD license; see LICENSE.txt

"""plugins/admin.py: Comprehensive implementation of admin commands; For
   administrator-level control of the bot."""

class Admin(object):
    type = "command"
    permissions = "admin"
    name = "Admin"
    desc = "Administrator commands"
    commands = {"quit": 0, "join": 1, "part": 1, "nick": 1}

    def __init__(self, api, msg):
        self.api = api
        self.msg = msg

    def command_quit(self, args):
        # BUG Can't get reason to work?
        reason = "Quitting"
        if args:
            reason = " ".join(args)
        self.api.grubbot.connection.send("quit", reason)

    def command_join(self, args):
        channels = args
    
        if len(channels) > 10:
            self.api.grubbot.reply(self.msg, "I will only join the first 10 channels.")
            channels = channels[0:10]        

        self.api.grubbot.connection.send("join", ",".join(channels))

    def command_part(self, args):
        channels = args
        self.api.grubbot.connection.send("part", ",".join(channels))

    def command_nick(self, args):
        nick = args[0]
        self.api.grubbot.connection.send("nick", nick) 

plugin = Admin